home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS 1.31 / h / PCCTSAST.h < prev   
Encoding:
C/C++ Source or Header  |  1995-03-10  |  4.1 KB  |  127 lines  |  [TEXT/MPS ]

  1. /* Abstract syntax tree
  2.  *
  3.  * SOFTWARE RIGHTS
  4.  *
  5.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  6.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  7.  * company may do whatever they wish with source code distributed with
  8.  * PCCTS or the code generated by PCCTS, including the incorporation of
  9.  * PCCTS, or its output, into commerical software.
  10.  * 
  11.  * We encourage users to develop software with PCCTS.  However, we do ask
  12.  * that credit is given to us for developing PCCTS.  By "credit",
  13.  * we mean that if you incorporate our source code into one of your
  14.  * programs (commercial product, research project, or otherwise) that you
  15.  * acknowledge this fact somewhere in the documentation, research report,
  16.  * etc...  If you like PCCTS and have developed a nice tool with the
  17.  * output, please mention that you developed it using PCCTS.  In
  18.  * addition, we ask that this header remain intact in our source code.
  19.  * As long as these guidelines are kept, we expect to continue enhancing
  20.  * this system and expect to make other tools available as they are
  21.  * completed.
  22.  *
  23.  * ANTLR 1.31
  24.  * Terence Parr
  25.  * Parr Research Corporation
  26.  * with Purdue University and AHPCRC, University of Minnesota
  27.  * 1989-1995
  28.  */
  29.  
  30. #ifndef PCCTSAST_H
  31. #define PCCTSAST_H
  32.  
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include "config.h"
  36. class List;
  37.  
  38. #define StringScanMaxText    50
  39. #define MaxTreeStackDepth    400
  40.  
  41. typedef struct stringlexer {
  42.             signed int c;
  43.             char *input;
  44.             char *p;
  45.             char text[StringScanMaxText];
  46.         } StringLexer;
  47.  
  48. /* Define the structures needed for ast_scan() */
  49. typedef struct stringparser {
  50.             int token;
  51.             StringLexer *lexer;
  52.             int num_labels;
  53.         } StringParser;
  54.  
  55. typedef struct _scanast {
  56.             struct _scanast *right, *down;
  57.             int token;
  58.             int label_num;
  59.         } ScanAST;
  60.  
  61. #define VALID_SCAN_TOKEN(t)        (t>=LPAREN && t<=PERIOD)
  62.  
  63. class PCCTS_AST {
  64. protected:
  65.     static char *scan_token_tbl[];
  66.     unsigned const LPAREN=1;
  67.     unsigned const RPAREN=2;
  68.     unsigned const PERCENT=3;
  69.     unsigned const INT=4;
  70.     unsigned const COLON=5;
  71.     unsigned const POUND=6;
  72.     unsigned const PERIOD=7;
  73.     const StringScanEOF=-1;
  74.  
  75. protected:
  76.     char *scan_token_str(int t);
  77.     void stringlexer_init(StringLexer *scanner, char *input);
  78.     void stringparser_init(StringParser *, StringLexer *);
  79.     ScanAST *stringparser_parse_scanast(char *templ, int *n);
  80.     ScanAST *stringparser_parse_tree(StringParser *parser);
  81.     ScanAST *stringparser_parse_element(StringParser *parser);
  82.     void stringscan_advance(StringLexer *scanner);
  83.     int stringscan_gettok(StringLexer *scanner);
  84.     void _push(PCCTS_AST **st, int *sp, PCCTS_AST *e);
  85.     PCCTS_AST *_pop(PCCTS_AST **st, int *sp);
  86.     int match_partial(PCCTS_AST *t, PCCTS_AST *u);
  87.     int scanmatch(ScanAST *t, PCCTS_AST **labels[], int *n);
  88.     void scanast_free(ScanAST *t);
  89.     ScanAST *new_scanast(int tok);
  90.     void stringparser_match(StringParser *parser, int token);
  91.  
  92. public:
  93.     PCCTS_AST()    {;}
  94.     virtual ~PCCTS_AST() {;}
  95.  
  96.     /* This group must be defined for SORCERER to work correctly */
  97.     virtual PCCTS_AST *right() = 0;
  98.     virtual PCCTS_AST *down() = 0;
  99.     virtual void setRight(PCCTS_AST *t) = 0;
  100.     virtual void setDown(PCCTS_AST *t) = 0;
  101.     virtual int token() { return 0; }    // we define these so ANTLR doesn't have to
  102.     virtual void setToken(int t) {;}
  103.  
  104.     /* These are not needed by ANTLR, but are support functions */
  105.     virtual void addChild(PCCTS_AST *t);
  106.     virtual void lisp_action(FILE *f) {;}
  107.     virtual void lisp(FILE *f);
  108.     static PCCTS_AST *make(PCCTS_AST *rt, ...);
  109.     virtual PCCTS_AST *find_all(PCCTS_AST *t, PCCTS_AST *u, PCCTS_AST **cursor);
  110.     virtual int match(PCCTS_AST *t, PCCTS_AST *u);
  111.     virtual void insert_after(PCCTS_AST *a, PCCTS_AST *b);
  112.     virtual void append(PCCTS_AST *a, PCCTS_AST *b);
  113.     virtual PCCTS_AST *tail(PCCTS_AST *a);
  114.     virtual PCCTS_AST *bottom(PCCTS_AST *a);
  115.     virtual PCCTS_AST *cut_between(PCCTS_AST *a, PCCTS_AST *b);
  116.     virtual List *to_slist(PCCTS_AST *t);
  117.     virtual void tfree(PCCTS_AST *t);
  118.     virtual int ast_scan(char *templ, ...);
  119.     virtual int nsiblings(PCCTS_AST *t);
  120.     virtual PCCTS_AST *sibling_index(PCCTS_AST *t, int i);
  121.  
  122.     require(int e,char *err){ if ( !e ) panic(err); }
  123.     virtual panic(char *err){ fprintf(stderr, "PCCTS_AST: %s\n", err); exit(1); }
  124. };
  125.  
  126. #endif /* PCCTSAST_H */
  127.